package at.fhooe.mcm12.java.sensors;

import java.rmi.RemoteException;
import java.util.Vector;
import at.fhooe.mcm12.java.enums.SensorType;
import at.fhooe.mcm12.java.interfaces.ISensorListener;

public abstract class PushSensor extends AbstractSensor implements Runnable{
	
	protected PushSensor() throws RemoteException {
		super();
	}

	protected Vector<ISensorListener> m_sensorListener;
	protected int m_updateInterval;
	
	public abstract void push();
	
	public void addSensorListener(ISensorListener _listener)
	{
		if(_listener != null && !m_sensorListener.contains(_listener))
		{
			m_sensorListener.add(_listener);
		}
	}
	
	public void removeSensorListener(ISensorListener _listener)
	{
		if(_listener != null && m_sensorListener.contains(_listener))
		{
			m_sensorListener.remove(_listener);
		}
	}
	
	public int getUpdateInterval()
	{
		return m_updateInterval;
	}
	
	public void setUpdateInterval(int _updateInterval)
	{
		m_updateInterval = _updateInterval;
	}
	
	public SensorType getSensorType()
	{
		return SensorType.Push;
	}
	
	public void run()
	{
		try
		{
			while(true)
			{
				Thread.sleep(m_updateInterval);
				
				if(isActive()){
					push();
				}
			}
		}
		catch(InterruptedException ie)
		{
			System.err.println(ie.getMessage());
		}
	}
}
